package com.legrand.www.module.worker.controller;

import com.legrand.www.module.core.annotation.RolePermission;
import com.legrand.www.module.core.redis.RedisUtils;
import com.legrand.www.module.exception.exception.CustomizeException;
import com.legrand.www.module.worker.entity.Teacher;
import com.legrand.www.module.worker.feign.UserFeignServer;
import com.legrand.www.module.worker.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/worker")
/**
 *@author xiah
 *2018-06-26 05:11:16
 * 该类用来测试 统一异常处理  切面权限控制
 */
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private UserFeignServer userFeignServer;
    @Autowired
    private RedisUtils redisUtils;

    /**
     * 限流测试
     */
    @RequestMapping("/test")
    @ResponseBody
    public String test() {
        redisUtils.set("123", "hello world");
        System.out.println("进入了方法");
        String string = redisUtils.get("123").toString();
        return string;
    }

    /**
     * 限流测试
     */
    @RequestMapping("/rr")
    @ResponseBody
    public String test2() {
        System.out.println("我不限制次数");
        return "我不限制次数";
    }

    @RequestMapping("/getTeacher")
    @ResponseBody
    public Teacher getTeacher() {
        return teacherService.getTeacher();
    }

    /**
     * @author xiah
     * 2018-06-26 05:09:59
     * 统一异常处理测试 抛出/by 0 错误
     */
    @RequestMapping("/getUserName")
    @ResponseBody
    public String getUserName() {
        Integer a = 1;
        Integer b = 0;
        throw new CustomizeException("111", "sdfsd");
        //Integer c = a / b;
        //return userFeignServer.getUserName();
    }

    /**
     * @author xiah
     * 2018-06-26 05:09:25
     * 切面权限测试
     */
    @RequestMapping("/rightTest")
    @RolePermission(roles = {"worker"}, note = "能调用该接口的角色")
    @ResponseBody
    public String rightTest() {
        return "调用成功，拥有该权限";
    }


}
